package com.leqiang222.service_ribbon;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @Author LeQiang Li
 * @Date Created in 16:36 2019/4/4
 * @Description:
 * @Modified By:
 */
@Service
public class HelloService {
    @Autowired
    RestTemplate restTemplate;

    /*
    public String hiService(String name) {
        String url = "http://" + "eurka-client/" + "hi?name=";
        return restTemplate.getForObject(url + name, String.class);
    }
    */

    @HystrixCommand(fallbackMethod = "hiError")
    public String hiService(String name) {
        String url = "http://" + "eurka-client/" + "hi?name=";
        return restTemplate.getForObject(url + name, String.class);
    }

    public String hiError(String name) {
        return "hi,"+name+",sorry,error!";
    }
}
